package com.chapter9;

import java.util.Stack;

public class MyQueue2 {

	Stack<Integer> s1;
	Stack<Integer> s2;
	
	MyQueue2(){
		s1 = new Stack<Integer>();
		s2= new Stack<Integer>();
	}
	
	private void swap(Stack<Integer> s1, Stack<Integer> s2){
		Stack<Integer> t=s1;
		s1=s2;
		s2=t;
	}
	public void enqueue(int val){
		s1.push(val);
	}
	
	public int dequeue() throws Exception{
		if(s1.isEmpty() && s2.isEmpty())
			throw new Exception();
		if(s2.isEmpty()){
			while(!s1.isEmpty()){
				s2.push(s1.pop());
			}
			return s2.pop();
		}
		return s2.pop();
	}
}
